/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.navdata;

import java.util.ArrayList;

import fr.uha.ensisa.jmp.drone.app.DroneConstants;
import fr.uha.ensisa.jmp.drone.navdata.options.OptionsVistor;


public class Navdata
{
	private int header;
	private int sequenceNumber;
	private int state;
	private int visionFlag;
	
	private ArrayList<NavdataOption> options;
	
	public void update (int header, int sequenceNumber, int state, int visionFlag)
	{
			this.header = header;
			this.sequenceNumber = sequenceNumber;
			this.state = state;
			this.visionFlag = visionFlag;
			this.visionFlag = visionFlag;
	}
	
	public void options(ArrayList<NavdataOption> options)
	{
		this.options = options;
	}
	
	public  boolean isValidHeader()
	{
		return this.header == DroneConstants.NAVDATA_HEADER;
	}
	
	public  boolean isInBootstrapMode()
	{
		return DroneState.isInBootstrapMode(this.state);
	}

	public  boolean isInNavDemoMode()
	{
		return DroneState.isInNavDemoMode(this.state);
	}

	public  boolean isComWatchdogEnabled()
	{
		return DroneState.isComWatchdogEnabled(this.state);
	}
		
	public  boolean isCommandProcessing()
	{
		return DroneState.isCommandProcessing(this.state);
	}
		
	public int sequenceNumber()
	{
		return this.sequenceNumber;
	}
	
	public void accept(OptionsVistor v)
	{
		if (this.options == null) return;
		for(NavdataOption o: options)
			o.accept(v);
	}

	public  String toString()
	{
		StringBuilder tmp = new StringBuilder('[');
		tmp.append(Integer.toHexString(this.header)).append(", ");
		tmp.append(Integer.toBinaryString(this.state)).append(", ");
		tmp.append(this.sequenceNumber).append(", ");
		tmp.append(this.visionFlag).append(", ...");
		tmp.append(']');
		return tmp.toString();
	}

	

}
